//
//  NameHolder.m
//  TabNav
//
//  Created by Kalyan Mudumbai on 8/29/10.
//  Copyright 2010 GOLDMAN SACHS. All rights reserved.
//

#import "NameHolder.h"


@implementation NameHolder
//@synthesize nameStringArray;
//@synthesize shortDescStringArray;
@synthesize actualData;
@synthesize nameDataDictArray;

-(void) loadNames {
	//load the names
	NSBundle * bundle = [NSBundle mainBundle];
	NSString * plistPath = [bundle pathForResource:@"All-Names" ofType:@"plist"];
	NSLog(@"plist path is: %@", plistPath);
	NSArray * namesForSlokas = [[NSArray alloc] initWithContentsOfFile:plistPath];
	self.actualData = namesForSlokas;
	
	nameDataDictArray = [[NSMutableArray alloc] init];
	
	nameStringArray = [[NSMutableArray alloc] init];
	shortDescStringArray = [[NSMutableArray alloc] init];
		
	// arrays for holding data per sloka basis
	nameStringsForSlokaArray = [[NSMutableArray alloc] init];
	sdStringForSlokaArray = [[NSMutableArray alloc] init];	
	
	for(id namesForSloka in namesForSlokas) {
		NSArray * namesArray = (NSArray*)namesForSloka;
		
		NSMutableArray * namesForThisSloka = [[NSMutableArray alloc] init];
		NSMutableArray * sdsForThisSloka = [[NSMutableArray alloc] init];
		
		for(id nameDict in namesArray) {
			NSDictionary * nsd = (NSDictionary*) nameDict;
			NSString * name = [nsd objectForKey:@"name"];
			NSString * sd = [nsd objectForKey:@"sd"];
			
			[nameStringArray addObject:name];
			[shortDescStringArray addObject:sd];
			
			[namesForThisSloka addObject:name];
			[sdsForThisSloka addObject:sd];
			[nameDataDictArray addObject:nsd];
			
		}
		
		[nameStringsForSlokaArray addObject:namesForThisSloka];
		[sdStringForSlokaArray addObject:sdsForThisSloka];
		
		[namesForThisSloka release];
		[sdsForThisSloka release];
	}
	
	NSLog(@"All names: %@", nameStringArray);
	NSLog(@"All sds: %@", shortDescStringArray);
	NSLog(@"Names per sloka: %@",nameStringsForSlokaArray);
	NSLog(@"SDs per sloka: %@",sdStringForSlokaArray);
	
}

-(NSArray*) getAllNameStrings {
	return nameStringArray;
}

-(NSArray*) getAllShortDescriptionStrings {
	return shortDescStringArray;
}

-(NSArray*) getNameStringsForSlokaNumber:(NSUInteger)slokaNumber {
	return [nameStringsForSlokaArray objectAtIndex:slokaNumber];
}

-(NSArray*) getShortDescriptionStringsForSlokaNumber:(NSUInteger)slokaNumber {
	return [sdStringForSlokaArray objectAtIndex:slokaNumber];
}

-(NSDictionary*) getDataForNameId:(NSUInteger)nameId InSloka:(NSUInteger)slokaNumber {
	NSArray * namesForSlokam = (NSArray*)[actualData objectAtIndex:slokaNumber];
	return (NSDictionary*)[namesForSlokam objectAtIndex:nameId];
}

-(NSDictionary*) getDataForNameId:(NSUInteger)nameId {
	return [nameDataDictArray objectAtIndex:nameId];
}

-(void) dealloc {
	[nameStringArray release];
	[shortDescStringArray release];
	[nameStringsForSlokaArray release];
	[sdStringForSlokaArray release];
	[nameDataDictArray release];
	[super dealloc];
}

@end
